
//% color="#cf1256" iconWidth=50 iconHeight=40
namespace Mino{
    //% block="数据传输" blockType="command"  
    export function SshInit_rp(parameter: any, block: any) {        
        Generator.addImport(`\nimport filetocode2\nfrom runinssh2 import RUNSSH2 \nRUNSSH2("192.168.149.1",22,"pi","raspberry","/home/pi/SpiderPi/Functions/A_class.py").run()\n`);
        Generator.addImport('\nfrom minopi import mino\nfrom minopiadd import minoadd');
        Generator.addCode(`\na = mino()\nt = minoadd()`);  
    }
     //% block="行动 方向[FBLR] 步幅:[BMP] 时间:[TIME] 次数:[NUM]" blockType="command"
    //% FBLR.shadow="dropdown"  FBLR.options="FBLR"
     //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=500   BMP.defl=50
    //% TIME.shadow="range"  TIME.params.min=0    TIME.params.max=1000  TIME.defl=30
    //% NUM.shadow="range"   NUM.params.min=0    NUM.params.max=100    NUM.defl=1
    export function fblr(parameter: any, block: any) {
        var fblr=parameter.FBLR.code;
        var bmp=parameter.BMP.code;
        var time=parameter.TIME.code;
        var num=parameter.NUM.code;
        Generator.addCode(`\nif "${fblr}"=="go":\n    a.Ik_go(${bmp},${time},${num})`)
        Generator.addCode(`\nif "${fblr}"=="back":\n  a.Ik_back(${bmp},${time},${num})`)
        Generator.addCode(`\nif "${fblr}"=="left":\n  a.Ik_left(${bmp},${time},${num})`)
        Generator.addCode(`\nif "${fblr}"=="right":\n a.Ik_right(${bmp},${time},${num})`);      
    }   
     //% block="原地转弯 方向[LRTURN] 步幅:[BMP] 时间:[TIME] 次数:[NUM]" blockType="command"
    //% LRTURN.shadow="dropdown"  LRTURN.options="LRTURN"
     //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=500   BMP.defl=50
    //% TIME.shadow="range"  TIME.params.min=0    TIME.params.max=1000  TIME.defl=30
    //% NUM.shadow="range"   NUM.params.min=0    NUM.params.max=100    NUM.defl=1
    export function lr_turn(parameter: any, block: any) {
        var lrturn=parameter.LRTURN.code;
        var bmp=parameter.BMP.code;
        var time=parameter.TIME.code;
        var num=parameter.NUM.code;
        Generator.addCode(`\nif "${lrturn}"=="left_turn":\n    a.Ik_left_turn(${bmp},${time},${num})`)
        Generator.addCode(`\nif "${lrturn}"=="right_turn":\n   a.Ik_right_turn(${bmp},${time},${num})`)     
    }   

    //% block="舵机控制 ID:[ID] 角度:[BMP] 时间:[TIME] " blockType="command"
    //% ID.shadow="range"   ID.params.min=19    ID.params.max=29    ID.defl=19
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=1000  BMP.defl=500
    //% TIME.shadow="range"   TIME.params.min=0    TIME.params.max=10000    TIME.defl=1000
    export function motor_control(parameter: any, block: any)
     {
        var id=parameter.ID.code;
        var bmp=parameter.BMP.code;
        var time=parameter.TIME.code;  
        Generator.addCode(`t.motor_control(${id},${bmp},${time})`);    
          
    }   
    //% block="寻找色块 颜色[COLOOR] 中心点_X:[X] 中心点_Y:[Y] 范围_前后:[FB] 范围_左右:[LR] 步幅:[BMP] 时间:[TIME] 其他:[OTHER]" blockType="command"
     //% COLOOR.shadow="dropdown"  COLOOR.options="COLOOR"   
    //% X.shadow="range"   X.params.min=0   X.params.max=640   X.defl=305
    //% Y.shadow="range"   Y.params.min=0    Y.params.max=480  Y.defl=320
    //% FB.shadow="range"   FB.params.min=0    FB.params.max=100    FB.defl=50
    //% LR.shadow="range"   LR.params.min=0   LR.params.max=100   LR.defl=50
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=300  BMP.defl=50
    //% TIME.shadow="range"   TIME.params.min=0    TIME.params.max=5000    TIME.defl=30
    //% OTHER.shadow="range"   OTHER.params.min=0    OTHER.params.max=325    OTHER.defl=30
    export function search(parameter: any, block: any) {
        var coloor=parameter.COLOOR.code;
        var x=parameter.X.code;
        var y=parameter.Y.code;
        var fb=parameter.FB.code;
        var lr=parameter.LR.code;
        var bmp=parameter.BMP.code;
        var time=parameter.TIME.code;
        var other=parameter.OTHER.code;
        Generator.addCode(`a.search("${coloor}",10,90000,${x},${y},${fb},${lr},${bmp},${time},0,640,0,480,${other},7)`);    
    }   
     //% block="寻找黑框 目标大小_MIN:[MIN] 目标大小_MAX:[MAX] 中心_X:[X] 中心_Y:[Y] 画面宽:[X1] [X1CM] 画面高:[Y1] [Y1CM]" blockType="command" 
    //% MIN.shadow="range"   MIN.params.min=0   MIN.params.max=90000   MIN.defl=100
    //% MAX.shadow="range"   MAX.params.min=0    MAX.params.max=90000  MAX.defl=6000
    //% X.shadow="range"   X.params.min=0    X.params.max=1000    X.defl=305
    //% Y.shadow="range"   Y.params.min=0   Y.params.max=1000  Y.defl=320
    //% X1.shadow="range"   X1.params.min=0    X1.params.max=10000  X1.defl=200
    //% X1CM.shadow="range"   X1CME.params.min=0    X1CM.params.max=5000    X1CM.defl=200
    //% Y1.shadow="range"   Y1.params.min=0    Y1.params.max=10000  Y1.defl=200
    //% Y1CM.shadow="range"   Y1CME.params.min=0    Y1CM.params.max=5000    Y1CM.defl=200
    export function black_search(parameter: any, block: any) {
        var min=parameter.MIN.code;
        var max=parameter.MAX.code;
        var x=parameter.X.code;
        var y=parameter.Y.code;
        var x1=parameter.X1.code;
        var x1cm=parameter.X1CM.code;
        var y1=parameter.Y1.code;
        var y1cm=parameter.Y1CM.code;
        
        Generator.addCode(`a.search("black",${min},${max},${x},${y},30,30,50,30,${x1},${x1cm},${y1},${y1cm},324,1)`);    
    }   


    
    //% block="执行动作 名称[TEXT] 次数:[NUM] " blockType="command"
    //% TEXT.shadow="string" TEXT.defl="Mino"
    //% NUM.shadow="range"   NUM.params.min=0 NUM.params.max=50 NUM.defl=1
    export function Act(parameter: any, block: any) {
        var text=parameter.TEXT.code;
        var num=parameter.NUM.code;
        Generator.addCode(`a.Act(${text},${num})`);       
    }   
    //% block="等待超声波距离小于:[BMP] " blockType="command"
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=100   BMP.defl=25   
    export function wait_cm(parameter: any, block: any) {
        var bmp=parameter.BMP.code; 
        Generator.addCode(`a.wait_cm(${bmp})`);      
    } 
    //% block="距离物体距离:[BMP] " blockType="command"
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=100   BMP.defl=25   
    export function go_cm(parameter: any, block: any) {
        var bmp=parameter.BMP.code; 
        Generator.addCode(`a.go_cm(${bmp})`);      
    } 
     //% block="摄像头位置:上下[BMP]左右[CMP] " blockType="command"
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=1700   BMP.defl=1500
    //% CMP.shadow="range"   CMP.params.min=0    CMP.params.max=2500   CMP.defl=1500   
    export function intMove(parameter: any, block: any) {
        var bmp=parameter.BMP.code; 
        var cmp=parameter.CMP.code; 
        Generator.addCode(`t.intMove(${bmp},${cmp})`);      
    } 
     //% block="蜂鸣器鸣叫:时间[BMP]" blockType="command"
    //% BMP.shadow="range"   BMP.params.min=0    BMP.params.max=5   BMP.defl=1
    export function Buzz(parameter: any, block: any) {
        var bmp=parameter.BMP.code;       
        Generator.addCode(`a.Buzz(${bmp})`);      
    } 
    function replaceQuotationMarks(str:string){
            str=str.replace(/"/g, ""); //去除所有引号
            return str
    }


    
}
